//
//  YGBasicViewController.swift
//  sinaWeiBoGui
//
//  Created by liyonggui on 16/5/10.
//  Copyright © 2016年 liyonggui. All rights reserved.
//

import UIKit

class YGBasicViewController: UITableViewController {
    
    var userLogin: Bool = YGUserAccountViewModel.sharedInstance.isUserLogin
    
    override func loadView() {
        
        if userLogin {
            // 已经登录，显示正常界面
            super.loadView()
        } else {
            // 没登录，要显示的界面
            view = visitorView
            
            // 设置代理
            visitorView.delegate = self
            
            if self is YGHomeViewController {
                visitorView.startRotationAnimation()
            } else if self is YGMessViewController {
                visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            } else if self is YGDiscViewController {
                visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            } else if self is YGProfViewController {
                visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            }
        }
        
        // 设置导航按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickLogin")
    }
    
    

    // MARK: - 懒加载
    lazy var visitorView: YGVisitorView = YGVisitorView()

}

// MARK: - 扩展
extension YGBasicViewController: YGVisitorViewDelegate {
    
    // 实现代理方法
    func visitorViewDidClickLogin() {
        print(__FUNCTION__)
    }
    func visitorViewDidClickRegister() {
        
        // modal出授权控制器
        let oauthVC = YGOauthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
}























